<template>
  <div class="layout">
    <el-container>
      <el-header>
        <div class="header-content">
          <h1>家政服务管理系统</h1>
          <div class="user-info">
            <span>欢迎，{{ $store.getters.realName }}</span>
            <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
                <el-icon><User /></el-icon>
                <el-icon><ArrowDown /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="profile">个人中心</el-dropdown-item>
                  <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      
      <el-container>
        <el-aside width="200px">
          <el-menu
            :default-active="$route.path"
            class="el-menu-vertical"
            router
          >
            <el-menu-item index="/dashboard">
              <el-icon><House /></el-icon>
              <span>首页</span>
            </el-menu-item>
            
            <el-menu-item index="/orders">
              <el-icon><Document /></el-icon>
              <span>订单管理</span>
            </el-menu-item>
            
            <el-menu-item index="/services">
              <el-icon><Setting /></el-icon>
              <span>家政服务管理</span>
            </el-menu-item>
            
            <el-menu-item index="/reviews">
              <el-icon><ChatDotRound /></el-icon>
              <span>评价管理</span>
            </el-menu-item>
            
            <el-menu-item
              v-if="$store.getters.userType === 1"
              index="/users"
            >
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </el-menu-item>
            
            <el-menu-item
              v-if="$store.getters.userType === 1"
              index="/staff"
            >
              <el-icon><Avatar /></el-icon>
              <span>服务人员管理</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'

export default {
  name: 'Layout',
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        this.handleLogout()
      } else if (command === 'profile') {
        this.$router.push('/profile')
      }
    },
    
    handleLogout() {
      this.$store.dispatch('logout')
      ElMessage.success('已退出登录')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.layout {
  height: 100vh;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
}

.el-dropdown-link {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.el-header {
  background-color: #409eff;
  color: white;
}

.el-aside {
  background-color: #f5f5f5;
  border-right: 1px solid #e0e0e0;
}

.el-main {
  background-color: #fff;
  padding: 20px;
}

.el-menu-vertical {
  border-right: none;
}
</style> 